package xiao.trip.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import xiao.trip.Do.happydo;
import xiao.trip.Do.saddo;
import xiao.trip.dao.happy;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@Controller
public class happycontroller {
    @Autowired
    happy HAPPY;
    @RequestMapping("/inserthappy")
    public String inserthappy(HttpServletRequest request,Map map)
    {
        String happy=request.getParameter("happy");
        List<happydo> ListHappy=new ArrayList<>();
        List<saddo> ListSad = new ArrayList<>();
        if(happy!=null)
        {
            HAPPY.inserthappy(happy);
        }
        else{
         ListHappy= HAPPY.selecthappy();
            ListSad= HAPPY.selectsad();
         map.put("ListHappy",ListHappy);
         map.put("ListSad",ListSad);
        }
        return "forward:happy";
    }
    @RequestMapping("/insertsad")
    public String insertsad(HttpServletRequest request,Map map)
    {
        String sad=request.getParameter("sad");
        List<happydo> ListHappy=new ArrayList<>();
        List<saddo> ListSad=new ArrayList<>();
        if(sad!=null)
        {
            HAPPY.insertsad(sad);
        }
        else{
            ListHappy= HAPPY.selecthappy();
            ListSad= HAPPY.selectsad();
            map.put("ListHappy",ListHappy);
            map.put("ListSad",ListSad);
        }
        return "forward:happy";
    }
    @RequestMapping("/happy")
    public String Happy(Map map)
    {
        List<happydo> ListHappy=new ArrayList<>();
        List<saddo> ListSad=new ArrayList<>();
        ListHappy= HAPPY.selecthappy();
        ListSad= HAPPY.selectsad();
        map.put("ListHappy",ListHappy);
        map.put("ListSad",ListSad);
        return "user/happy";
    }

}
